<?php

/**
 * Menashop
 *
 * LICENSE
 *
 * This source file is subject to the license that is bundled
 * with this project in the file LICENSE.txt
 *
 * @category   Zend
 * @package    Admin_Model
 * @subpackage CategoryFeature
 * @copyright  Copyright (c) 2011 Menashop UA Inc. (http://www.menashop.com.ua)
 * @license    LICENSE.txt
 * @version    1.0.0
 * @since      File available since Release 1.0.0
 */

/**
 * The domain for category feature
 * 
 * @category   Zend
 * @package    Admin_Model
 * @subpackage CategoryFeature
 * @copyright  Copyright (c) 2011 Menashop UA Inc. (http://www.menashop.com.ua)
 * @license    LICENSE.txt
 */
class Admin_Model_CategoryFeature extends Zend_Db_Table_Abstract
{

    /**
     * The name of table
     * @var string 
     */
    protected $_name = 'category_feature';

    /**
     * Save category feature
     * @param array $row 
     */
    public function save($row)
    {
        // check ID (insert or update)
        $id = isset($row['id']) ? $row['id'] : null;
        if ($id) {
            unset($row['id']);
            $this->update($row, array('id = ?' => $id));
        } else {
            $this->insert($row);
        }
    }

    /**
     * Find ID of category feature by content ID
     * @param integer $contentId
     * @return integer 
     */
    public function findIdByContentId($contentId)
    {
        // find category feature by Content ID in database
        $query = $this->getAdapter()->select();
        $query->from($this->_name, 'id');
        $query->where('content_id = ?', $contentId);
        $result = $this->getAdapter()->fetchOne($query);
        return $result;
    }

}

